package com.zhumei.keyscale.util;

import android.content.*;
import java.util.concurrent.*;
import java.util.*;
import android.os.*;
import android.util.*;
import android.media.*;

public class MediaPlayUtil
{
    private static volatile MediaPlayUtil mVoicePlay;
    private Context mContext;
    private ExecutorService mExecutorService;
    
    private MediaPlayUtil(final Context mContext) {
        this.mContext = mContext;
        this.mExecutorService = Executors.newCachedThreadPool();
    }
    
    private void executeStart(final VoiceBuilder voiceBuilder) {
        final List<String> genVoiceList = VoiceTextTemplate.genVoiceList(voiceBuilder);
        if (genVoiceList != null) {
            if (genVoiceList.isEmpty()) {
                return;
            }
            this.mExecutorService.execute(new Runnable() {
                @Override
                public void run() {
                    MediaPlayUtil.this.start(genVoiceList);
                }
            });
        }
    }
    
    private boolean setPlaySpeed(final MediaPlayer mediaPlayer, final float speed) {
        if (Build$VERSION.SDK_INT >= 23) {
            Log.e("ContentValues", "setPlaySpeed3333: ");
            try {
                final PlaybackParams playbackParams = mediaPlayer.getPlaybackParams();
                playbackParams.setSpeed(speed);
                mediaPlayer.setPlaybackParams(playbackParams);
                return true;
            }
            catch (Exception ex) {
                Log.e("ContentValues", "setPlaySpeed: ", (Throwable)ex);
            }
        }
        return false;
    }
    
    private void start(final List<String> p0) {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     1: monitorenter   
        //     2: new             Ljava/util/concurrent/CountDownLatch;
        //     5: dup            
        //     6: iconst_1       
        //     7: invokespecial   java/util/concurrent/CountDownLatch.<init>:(I)V
        //    10: astore          6
        //    12: aconst_null    
        //    13: astore          5
        //    15: aconst_null    
        //    16: astore          4
        //    18: aload           4
        //    20: astore_2       
        //    21: aload           5
        //    23: astore_3       
        //    24: iconst_1       
        //    25: newarray        I
        //    27: astore          7
        //    29: aload           7
        //    31: iconst_0       
        //    32: iconst_0       
        //    33: iastore        
        //    34: aload           4
        //    36: astore_2       
        //    37: aload           5
        //    39: astore_3       
        //    40: aload_0        
        //    41: getfield        com/zhumei/keyscale/util/MediaPlayUtil.mContext:Landroid/content/Context;
        //    44: ldc             "tts_%s.mp3"
        //    46: iconst_1       
        //    47: anewarray       Ljava/lang/Object;
        //    50: dup            
        //    51: iconst_0       
        //    52: aload_1        
        //    53: aload           7
        //    55: iconst_0       
        //    56: iaload         
        //    57: invokeinterface java/util/List.get:(I)Ljava/lang/Object;
        //    62: aastore        
        //    63: invokestatic    java/lang/String.format:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
        //    66: invokestatic    com/zhumei/keyscale/util/FileUtils.getAssetFileDescription:(Landroid/content/Context;Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;
        //    69: astore          4
        //    71: aload           4
        //    73: astore_2       
        //    74: aload           4
        //    76: astore_3       
        //    77: new             Landroid/media/MediaPlayer;
        //    80: dup            
        //    81: invokespecial   android/media/MediaPlayer.<init>:()V
        //    84: astore          5
        //    86: aload           4
        //    88: astore_2       
        //    89: aload           4
        //    91: astore_3       
        //    92: aload           5
        //    94: aload           4
        //    96: invokevirtual   android/content/res/AssetFileDescriptor.getFileDescriptor:()Ljava/io/FileDescriptor;
        //    99: aload           4
        //   101: invokevirtual   android/content/res/AssetFileDescriptor.getStartOffset:()J
        //   104: aload           4
        //   106: invokevirtual   android/content/res/AssetFileDescriptor.getLength:()J
        //   109: invokevirtual   android/media/MediaPlayer.setDataSource:(Ljava/io/FileDescriptor;JJ)V
        //   112: aload           4
        //   114: astore_2       
        //   115: aload           4
        //   117: astore_3       
        //   118: aload           5
        //   120: invokevirtual   android/media/MediaPlayer.prepareAsync:()V
        //   123: aload           4
        //   125: astore_2       
        //   126: aload           4
        //   128: astore_3       
        //   129: aload           5
        //   131: new             Lcom/zhumei/keyscale/util/MediaPlayUtil$2;
        //   134: dup            
        //   135: aload_0        
        //   136: aload           5
        //   138: invokespecial   com/zhumei/keyscale/util/MediaPlayUtil$2.<init>:(Lcom/zhumei/keyscale/util/MediaPlayUtil;Landroid/media/MediaPlayer;)V
        //   141: invokevirtual   android/media/MediaPlayer.setOnPreparedListener:(Landroid/media/MediaPlayer$OnPreparedListener;)V
        //   144: aload           4
        //   146: astore_2       
        //   147: aload           4
        //   149: astore_3       
        //   150: aload           5
        //   152: new             Lcom/zhumei/keyscale/util/MediaPlayUtil$3;
        //   155: dup            
        //   156: aload_0        
        //   157: aload           7
        //   159: aload_1        
        //   160: aload           6
        //   162: invokespecial   com/zhumei/keyscale/util/MediaPlayUtil$3.<init>:(Lcom/zhumei/keyscale/util/MediaPlayUtil;[ILjava/util/List;Ljava/util/concurrent/CountDownLatch;)V
        //   165: invokevirtual   android/media/MediaPlayer.setOnCompletionListener:(Landroid/media/MediaPlayer$OnCompletionListener;)V
        //   168: aload           4
        //   170: ifnull          222
        //   173: aload           4
        //   175: invokevirtual   android/content/res/AssetFileDescriptor.close:()V
        //   178: goto            222
        //   181: astore_1       
        //   182: aload_1        
        //   183: invokevirtual   java/io/IOException.printStackTrace:()V
        //   186: goto            222
        //   189: astore_1       
        //   190: goto            242
        //   193: astore_1       
        //   194: aload_3        
        //   195: astore_2       
        //   196: aload_1        
        //   197: invokevirtual   java/lang/Exception.printStackTrace:()V
        //   200: aload_3        
        //   201: astore_2       
        //   202: aload           6
        //   204: invokevirtual   java/util/concurrent/CountDownLatch.countDown:()V
        //   207: aload_3        
        //   208: ifnull          222
        //   211: aload_3        
        //   212: invokevirtual   android/content/res/AssetFileDescriptor.close:()V
        //   215: goto            222
        //   218: astore_1       
        //   219: goto            182
        //   222: aload           6
        //   224: invokevirtual   java/util/concurrent/CountDownLatch.await:()V
        //   227: aload_0        
        //   228: invokevirtual   java/lang/Object.notifyAll:()V
        //   231: goto            239
        //   234: astore_1       
        //   235: aload_1        
        //   236: invokevirtual   java/lang/InterruptedException.printStackTrace:()V
        //   239: aload_0        
        //   240: monitorexit    
        //   241: return         
        //   242: aload_2        
        //   243: ifnull          258
        //   246: aload_2        
        //   247: invokevirtual   android/content/res/AssetFileDescriptor.close:()V
        //   250: goto            258
        //   253: astore_2       
        //   254: aload_2        
        //   255: invokevirtual   java/io/IOException.printStackTrace:()V
        //   258: aload_1        
        //   259: athrow         
        //   260: astore_1       
        //   261: aload_0        
        //   262: monitorexit    
        //   263: aload_1        
        //   264: athrow         
        //    Signature:
        //  (Ljava/util/List<Ljava/lang/String;>;)V
        //    Exceptions:
        //  Try           Handler
        //  Start  End    Start  End    Type                            
        //  -----  -----  -----  -----  --------------------------------
        //  2      12     260    265    Any
        //  24     29     193    222    Ljava/lang/Exception;
        //  24     29     189    260    Any
        //  40     71     193    222    Ljava/lang/Exception;
        //  40     71     189    260    Any
        //  77     86     193    222    Ljava/lang/Exception;
        //  77     86     189    260    Any
        //  92     112    193    222    Ljava/lang/Exception;
        //  92     112    189    260    Any
        //  118    123    193    222    Ljava/lang/Exception;
        //  118    123    189    260    Any
        //  129    144    193    222    Ljava/lang/Exception;
        //  129    144    189    260    Any
        //  150    168    193    222    Ljava/lang/Exception;
        //  150    168    189    260    Any
        //  173    178    181    182    Ljava/io/IOException;
        //  173    178    260    265    Any
        //  182    186    260    265    Any
        //  196    200    189    260    Any
        //  202    207    189    260    Any
        //  211    215    218    222    Ljava/io/IOException;
        //  211    215    260    265    Any
        //  222    231    234    239    Ljava/lang/InterruptedException;
        //  222    231    260    265    Any
        //  235    239    260    265    Any
        //  239    241    260    265    Any
        //  246    250    253    258    Ljava/io/IOException;
        //  246    250    260    265    Any
        //  254    258    260    265    Any
        //  258    260    260    265    Any
        //  261    263    260    265    Any
        // 
        // The error that occurred was:
        // 
        // java.lang.IndexOutOfBoundsException: Index: 145, Size: 145
        //     at java.util.ArrayList.rangeCheck(Unknown Source)
        //     at java.util.ArrayList.get(Unknown Source)
        //     at com.strobel.decompiler.ast.AstBuilder.convertToAst(AstBuilder.java:3321)
        //     at com.strobel.decompiler.ast.AstBuilder.convertToAst(AstBuilder.java:3569)
        //     at com.strobel.decompiler.ast.AstBuilder.convertToAst(AstBuilder.java:3435)
        //     at com.strobel.decompiler.ast.AstBuilder.build(AstBuilder.java:113)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:211)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:782)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:675)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:552)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:519)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:161)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:150)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:125)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.buildAst(JavaLanguage.java:71)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.decompileType(JavaLanguage.java:59)
        //     at us.deathmarine.luyten.FileSaver.doSaveJarDecompiled(FileSaver.java:192)
        //     at us.deathmarine.luyten.FileSaver.access$300(FileSaver.java:45)
        //     at us.deathmarine.luyten.FileSaver$4.run(FileSaver.java:112)
        //     at java.lang.Thread.run(Unknown Source)
        // 
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }
    
    public static MediaPlayUtil with(final Context context) {
        if (MediaPlayUtil.mVoicePlay == null) {
            synchronized (MediaPlayUtil.class) {
                if (MediaPlayUtil.mVoicePlay == null) {
                    MediaPlayUtil.mVoicePlay = new MediaPlayUtil(context);
                }
            }
        }
        return MediaPlayUtil.mVoicePlay;
    }
    
    public void checkMoney(final String s, final boolean b) {
        this.executeStart(new VoiceBuilder.Builder().start("pleasepay").money(s).unit("yuan").checkNum(b).builder());
    }
    
    public void play(final VoiceBuilder voiceBuilder) {
        this.executeStart(voiceBuilder);
    }
    
    public void play(final String s, final String s2) {
        this.play(s, s2, false);
    }
    
    public void play(final String s, final String s2, final boolean b) {
        if (s2.equals("1")) {
            this.executeStart(new VoiceBuilder.Builder().start("weixin").money(s).unit("yuan").checkNum(b).builder());
            return;
        }
        if (s2.equals("2")) {
            this.executeStart(new VoiceBuilder.Builder().start("zhifubao").money(s).unit("yuan").checkNum(b).builder());
            return;
        }
        if (s2.equals("3")) {
            this.executeStart(new VoiceBuilder.Builder().start("xianjin").money(s).unit("yuan").checkNum(b).builder());
            return;
        }
        if (s2.equals("4")) {
            this.executeStart(new VoiceBuilder.Builder().start("huiyuan").money(s).unit("yuan").checkNum(b).builder());
        }
    }
    
    public void play(final String s, final boolean b) {
        this.executeStart(new VoiceBuilder.Builder().start("success").money(s).unit("yuan").checkNum(b).builder());
    }
    
    public void play2(final String s) {
        this.executeStart(new VoiceBuilder.Builder().start("welcome").builder());
    }
}
